package com.my.log.config;

import com.my.event.listener.ApiLogListener;
import com.my.event.listener.ErrorLogListener;
import com.my.h2.logs.LogApiH2Dao;
import com.my.h2.logs.LogErrorH2Dao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author timo 2021/2/25
 */
@Configuration
@ConditionalOnWebApplication
//@EnableConfigurationProperties({BladeRequestLogProperties.class})
//@BladePropertySource("classpath:/blade-log.yml")
public class LogToolAutoConfiguration {
    public LogToolAutoConfiguration() {
    }

    @Bean
    public ApiLogAspect apiLogAspect() {
        return new ApiLogAspect();
    }


    @Autowired
    private LogApiH2Dao logApiH2Dao;
    @Autowired
    private LogErrorH2Dao logErrorH2Dao;


    @Bean
    @ConditionalOnMissingBean(
            name = {"apiLogListener"}
    )
    public ApiLogListener apiLogListener(){
        return new ApiLogListener(logApiH2Dao);
    }
//    public ApiLogListener apiLogListener(ILogClient logService, ServerInfo serverInfo, BladeProperties bladeProperties) {
//        return new ApiLogListener(logService, serverInfo, bladeProperties);
//    }

    @Bean
    @ConditionalOnMissingBean(
            name = {"errorEventListener"}
    )
    public ErrorLogListener errorEventListener(){
        return new ErrorLogListener(logErrorH2Dao);
    }
//    public ErrorLogListener errorEventListener(ILogClient logService, ServerInfo serverInfo, BladeProperties bladeProperties) {
//        return new ErrorLogListener(logService, serverInfo, bladeProperties);
//    }

}
